/**
 * Alipay.com Inc.
 * Copyright (c) 2004-2011 All Rights Reserved.
 */
package com.alipay.supergw.common.dal.share_supergw.manual.ibatis;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.dao.DataAccessException;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.alipay.supergw.common.dal.common.TddlHelper;
import com.alipay.supergw.common.dal.share_supergw.auto.daointerface.ClusterMappingDAO;
import com.alipay.supergw.common.dal.share_supergw.manual.dataobject.ClusterMappingDO;

/**
 * An ibatis based implementation of dao interface <tt>com.alipay.supergw.common.dal.share_supergw.auto.daointerface.ClusterMappingDAO</tt>.
 *
 * This file is generated by <tt>supergw-dalgen</tt>, a DAL (Data Access Layer)
 * code generation utility specially developed for <tt>supergw</tt> project.
 * 
 * PLEASE DO NOT MODIFY THIS FILE MANUALLY, or else your modification may
 * be OVERWRITTEN by someone else. To modify the file, you should go to 
 * directory <tt>(project-home)/dalgen</tt>, and 
 * find the corresponding configuration file (<tt>tables/sgw_cluster_mapping.xml</tt>). 
 * Modify the configuration file according to your needs, then run <tt>supergw-dalgen</tt> 
 * to generate this file.
 */
public class IbatisClusterMappingDAO extends SqlMapClientDaoSupport implements ClusterMappingDAO {

    /**
     *  Insert one <tt>ClusterMappingDO</tt> object to DB table <tt>sgw_cluster_mapping</tt>, return primary key
     *
     *  <p>
     *  Description for this operation is<br>
     *  <tt></tt>
     *  <p>
     *  The sql statement for this operation is <br>
     *  <tt>insert into sgw_cluster_mapping(cluster_id,channel_system_id,gmt_create,gmt_modified) values (?, ?, sysdate, sysdate)</tt>
     *
     *	@param clusterMapping
     *	@return String
     *	@throws DataAccessException
     */
    public String insert(ClusterMappingDO clusterMapping) throws DataAccessException {
        if (clusterMapping == null) {
            throw new IllegalArgumentException("Can't insert a null data object into db.");
        }

        getSqlMapClientTemplate().insert("MS-CLUSTER-MAPPING-INSERT", clusterMapping);

        return clusterMapping.getClusterId();
    }

    /**
     *  Query DB table <tt>sgw_cluster_mapping</tt> for records.
     *
     *  <p>
     *  Description for this operation is<br>
     *  <tt></tt>
     *  <p>
     *  The sql statement for this operation is <br>
     *  <tt>select cluster_id, channel_system_id, gmt_create, gmt_modified from sgw_cluster_mapping where ((channel_system_id = ?) AND (cluster_id = ?))</tt>
     *
     *	@param channelSystemId
     *	@param clusterId
     *	@return List<ClusterMappingDO>
     *	@throws DataAccessException
     */
    @SuppressWarnings({ "rawtypes", "unchecked" })
    public List<ClusterMappingDO> select(String channelSystemId, String clusterId)
                                                                                  throws DataAccessException {
        Map param = new HashMap();

        param.put("channelSystemId", channelSystemId);
        param.put("clusterId", clusterId);

        TddlHelper.skipSqlParse();

        return getSqlMapClientTemplate().queryForList("MS-CLUSTER-MAPPING-SELECT", param);

    }

    /**
     *  Delete records from DB table <tt>sgw_cluster_mapping</tt>.
     *
     *  <p>
     *  Description for this operation is<br>
     *  <tt></tt>
     *  <p>
     *  The sql statement for this operation is <br>
     *  <tt>delete from sgw_cluster_mapping where ((cluster_id = ?) AND (channel_system_id = ?))</tt>
     *
     *	@param clusterId
     *	@param channelSystemId
     *	@return int
     *	@throws DataAccessException
     */
    @SuppressWarnings({ "rawtypes", "unchecked" })
    public int delete(String clusterId, String channelSystemId) throws DataAccessException {
        Map param = new HashMap();

        param.put("clusterId", clusterId);
        param.put("channelSystemId", channelSystemId);

        return getSqlMapClientTemplate().delete("MS-CLUSTER-MAPPING-DELETE", param);
    }

}